package com.bwie.service.impl;

import com.bwie.common.domain.Happy;
import com.bwie.common.domain.Login;
import com.bwie.mapper.HappyMapper;
import com.bwie.mapper.LoginMapper;
import com.bwie.service.HappyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author：Minxiao Hao
 * @Description:
 * @name：HappyServiceImpl
 * @Date：2024/11/4 11:29
 */
@Service
public class HappyServiceImpl implements HappyService {
    @Autowired
    private HappyMapper happyMapper;
    @Autowired
    private LoginMapper loginMapper;

    /**
     * 活动列表展示
     * @return
     */
    @Override
    public List<Happy> findHappyList() {
        List<Happy> list = happyMapper.findHappyList();
        return list;
    }

    /**
     * 抽奖活动大转盘
     * @param happy
     * @return
     */
    @Override
    @Transactional
    public Happy happyTake(Happy happy) {
        //积分首先大于两千
        Login login = new Login();
        if (login.getLoginCount()>2000){
            login.setLoginCount(login.getLoginCount()-2000);
            //抽奖完成后 在原有事物的基础上-1
            happy.setHappyCount(happy.getHappyCount()-1);
            happyMapper.deleteHappyCount(happy.getHappyCount()-1);
        }

        return happy;
    }
}
